package com.ruoyi.eoms.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.eoms.domain.Agreement;
import com.ruoyi.eoms.service.IAgreementService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同管理Controller
 * 
 * @author yuanpingfang
 * @date 2020-12-01
 */
@RestController
@RequestMapping("/eoms/agreement")
public class AgreementController extends BaseController
{
    @Autowired
    private IAgreementService agreementService;

    /**
     * 查询合同管理列表
     */
    @PreAuthorize("@ss.hasPermi('eoms:agreement:list')")
    @GetMapping("/list")
    public TableDataInfo list(Agreement agreement)
    {
        startPage();
        List<Agreement> list = agreementService.selectAgreementList(agreement);
        return getDataTable(list);
    }

    /**
     * 导出合同管理列表
     */
    @PreAuthorize("@ss.hasPermi('eoms:agreement:export')")
    @Log(title = "合同管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Agreement agreement)
    {
        List<Agreement> list = agreementService.selectAgreementList(agreement);
        ExcelUtil<Agreement> util = new ExcelUtil<Agreement>(Agreement.class);
        return util.exportExcel(list, "agreement");
    }

    /**
     * 获取合同管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('eoms:agreement:query')")
    @GetMapping(value = "/{agreementId}")
    public AjaxResult getInfo(@PathVariable("agreementId") String agreementId)
    {
        return AjaxResult.success(agreementService.selectAgreementById(agreementId));
    }

    /**
     * 新增合同管理
     */
    @PreAuthorize("@ss.hasPermi('eoms:agreement:add')")
    @Log(title = "合同管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Agreement agreement)
    {
        return toAjax(agreementService.insertAgreement(agreement));
    }

    /**
     * 修改合同管理
     */
    @PreAuthorize("@ss.hasPermi('eoms:agreement:edit')")
    @Log(title = "合同管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Agreement agreement)
    {
        return toAjax(agreementService.updateAgreement(agreement));
    }

    /**
     * 删除合同管理
     */
    @PreAuthorize("@ss.hasPermi('eoms:agreement:remove')")
    @Log(title = "合同管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{agreementIds}")
    public AjaxResult remove(@PathVariable String[] agreementIds)
    {
        return toAjax(agreementService.deleteAgreementByIds(agreementIds));
    }
}
